#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>

//[name]-[xx].[yyy].[ext]
#define VERSION_START '-'
#define VERSION_SAT   '.'
long int get_version(char * name);

int main( int argc, char * argv[])
{
    long int ver;
    ver = get_version(argv[1]);
    printf("ver=%ld\n", ver);
    return 0;    
}

long int get_version(char * name)
{
    char * base = NULL;
    char * strtmp = NULL, * endptr = NULL;
    long int ver = 0;
    long int lnum = 0;

    if ( name == NULL )
        return -1;
    base = name;
    //! Get basename
    if( strstr(name, "/") != NULL)
        base = strrchr(name, '/')+1;

    strtmp = strrchr(base, VERSION_START);
    if( strtmp == NULL)
        return -1;
    strtmp++;
    lnum = strtol(strtmp, &endptr, 10);
    if( lnum == LONG_MIN || lnum == LONG_MAX )
        return -1;
    ver = lnum * 1000;
    if( endptr != NULL )
    {
        if(endptr[0] == VERSION_SAT)
        {
            strtmp = endptr + 1;
            lnum = strtol(strtmp, &endptr, 10);
            if( lnum == LONG_MIN || lnum == LONG_MAX )
                return -1;
            if( strtmp == endptr)
                return -1;
            ver += lnum;
        }else
            return -1;
    }
    return ver;
}
